package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.OrderRecommendService;
import cn.huiyunche.base.service.interfaces.UserJourneyService;
import cn.huiyunche.base.service.model.CJourney;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderRecommendServiceImpl implements OrderRecommendService {

    private static final Logger logger = LoggerFactory.getLogger(OrderRecommendServiceImpl.class);

    // @Autowired
    // private GDMapService mapService;

    @Autowired
    private UserJourneyService journeyService;

    @Async
    public void recommendForAddress(Long orderId, String orderDept, String orderDest) throws Exception {
        logger.info("recommendForAddress params orderId : {}, orderDept : {}, orderDest : {}.", orderId, orderDept, orderDest);
        //获取所有当前在线并当天上报过行程的用户
        List<CJourney> users = journeyService.selectTodayJourneyFromAllOnlineUsers();
        CJourney journey;
        if (CollectionUtils.isNotEmpty(users)) {
            for (int i = 0; i < users.size(); i++) {
                journey = users.get(i);
                //司机当前位置距离运单出发地位置
                // BigDecimal deptDistance = mapService.getDistanceByLongitudeAndLatitude(new StringBuffer(journey.getLongitude().toString()).append(",").append(journey.getLatitude()).toString(), mapService.getLongitudeAndLatitudeByAddress(orderDept));

                //司机目的地距离运单目的地位置
                // BigDecimal destDistance = new BigDecimal("501");
                if (StringUtils.isNotBlank(journey.getReceiptAddress())) {
//          destDistance = mapService.distance(journey.getReceiptAddress(), orderDest);
                }

                //若司机当前距离距离订单发运地或者司机当前目的地距离运单目的地<500公里则推荐
//        waybillMapper waybill = new waybillMapper();
//        recommend.setUserId(journey.getUserId());
//        recommend.setOrderId(orderId);
//        recommend.setStatus(OrderRecommendStatusEnum.RECOMMENDED.getValue());
//        if(!(-1==BigDecimal.valueOf((long)500).compareTo(deptDistance))){
//          recommend.setMatchCondition("司机当前位置");
//          recommendMapper.insertSelective(recommend);
//        }else if(!(-1==BigDecimal.valueOf((long)500).compareTo(destDistance))){
//          recommend.setMatchCondition("司机当前行程目的地");
//          recommendMapper.insertSelective(recommend);
//        }
            }
        }
    }


}
